<!DOCTYPE html>
<html class="x-admin-sm">

	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-X-admin2.2</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/xadmin.css">
		<script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/xadmin.js"></script>
		<!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
	</head>

	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a href="">基础设置</a>
				<a>
					<cite>绩效归档</cite></a>
			</span>
			<a class="layui-btn layui-btn-small select" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
			 title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
			</a>
		</div>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="shenhe"> <i class="layui-icon">&#xe857;</i>审核</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="fafang"> <i class="layui-icon">&#xe65e;</i>发放</a>
        </script>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">

						<div class="layui-card-body ">
							<table class="layui-table" lay-filter="table" id="table">

							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/html" id="toolbarDemo">
		<div class = "layui-btn-container" > 
            <button class = "layui-btn select layui-btn-sm" lay-event = "create_data" > <i class="layui-icon">&#xe621;</i> 生成绩效 </button>
        </div > 
    </script>

	<script>
		layui.use("laydate",
			function() {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: "#start" //指定元素
				});

				//执行一个laydate实例
				laydate.render({
					elem: "#end" //指定元素
				});

			});
	</script>
	<script>
		layui.use("table",
			function() {
				var table = layui.table;
				table.render({
					elem: "#table",
					toolbar: "#toolbarDemo",
					url: root + "Jixiaoshengcheng/get_list",
					page: true,
					cols: [
						[ //表头
							{
								align:"center",field: "id",
								title: "绩效号"
							}, {
								align:"center",field: "bonusname",
								title: "绩效名称"
							}, {
								align:"center",field: "account_date",
								title: "绩效日期"
							}, {
								align:"center",field: "statechecked",
								title: "是否审核",
								templet: function(res) {
									if (res.statechecked == 0) {
										return "否";
									}
									if (res.statechecked == 1) {
										return "是";
									}
								}
							}, {
								align:"center",field: "statearchived",
								title: "是否发放",
								templet: function(res) {
									if (res.statearchived == 0) {
										return "否";
									}
									if (res.statearchived == 1) {
										return "是";
									}
								}
							}, {
								align:"center",field: "createdate",
								title: "创建日期"
							}, {
								align:"center",fixed: "right",
								title: "操作",
								toolbar: "#barDemo",
								width: 150
							}
						]
					]
				});

				//监听单元格编辑
				table.on("tool(table)", function(obj) {

					var data = obj.data;
					//console.log(obj)
					if (obj.event === "del") {
						layer.confirm("真的删除行么", function(index) {
							// console.log(data.uuid);

							var uuid = data.uuid
							$.post(root + "index/table_delete", {
									uuid: uuid,
									table: "bonus_index"
								},
								function(data) {
									if (data.code == 0) {
										obj.del();
										layer.alert(data.msg, {
											icon: 6
										});
									} else {
										layer.alert(data.msg, {
											icon: 2
										});
									}
								}
							);

							layer.close(index);
						});
					}

					if (obj.event === "shenhe") {
						
						var data = obj.data;
						var value = data.statechecked;
						if(value == 1)
						{
							layer.msg("已审核，无法再次审核");
							return false;
						}
						
						value = 1;
						
						layer.confirm('确定审核？', {
							btn: ['确定', '取消']
						}, function(index, layero) {
							
							$.post(root + "Jixiaoshengcheng/set_field", {
									id: data.id,
									col: "statechecked",
									value:value
								},
								function(data) {
									if (data.code == 0) {
										
										layer.alert(data.msg, {
											icon: 6
										});
										
										table.reload('table',
											{
												
											}
										)
										
									} else {
										layer.alert(data.msg, {
											icon: 2
										});
									}
									
								}
							);
							
						}, function(index) {
							//按钮【按钮二】的回调
						});
					}

					if (obj.event === "fafang") {

						var data = obj.data;
						var shenhe = data.statechecked;
						if(shenhe != 1)
						{
							layer.msg("未审核，不可发放");
							return false;
						}
						var value = data.statearchived;
						
						if(value == 1)
						{
							layer.msg("已发放，无法再次发放");
							return false;
						}
						
						if(value == 0 || value == "")
						{
							value = 1;
						}
						else
						{
							value = 0;
						}
						
						
						
						layer.confirm('确定发放？', {
							btn: ['确定', '取消']
						}, function(index, layero) {
							
							$.post(root + "Jixiaoshengcheng/set_field", {
									id: data.id,
									col: "statearchived",
									value:value
								},
								function(data) {
									if (data.code == 0) {
										
										layer.alert(data.msg, {
											icon: 6
										});
										table.reload('table',
											{
												
											}
										)
									} else {
										layer.alert(data.msg, {
											icon: 2
										});
									}
								}
							);
							
						}, function(index) {
							//按钮【按钮二】的回调
						});

					}

				});
				table.on("tool(test)",
					function(obj) {




					});

				//头工具栏事件
				table.on("toolbar(table)",
					function(obj) {
						var checkStatus = table.checkStatus(obj.config.id);
						switch (obj.event) {
							case "create_data":
								xadmin.open("生成绩效", "create_data.html", 800, 600)
								break;
							case "getCheckLength":
								var data = checkStatus.data;
								layer.msg("选中了：" + data.length + " 个");
								break;
							case "isAll":
								layer.msg(checkStatus.isAll ? "全选" : "未全选");
								break;
						};
					});
					
				set_role_list("绩效生成");
				
				
			});
	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
	</script>

</html>
